<?php

class T4Site extends T4Node
{

##
# Perspective
##
	
protected $sPerspective = "user";
	
/**
 * Static interface to get active Perspective
 * @return string Current perspective
 */
public function getPerspective()
	{
	return $this->sPerspective ? $this->sPerspective : ($this->sPerspective = $this->sDefaultPerspective);
	}
	
##
# Wrapping
##

protected $sWrapTemplate = "", $mWrapParams = "";
		
/**
 * Redefine WrapTemplate used in show()
 * @param $sTemplate string Template name to be processed
 * @param $Request T4Request Context
 * @return T4Nod $this UPC-Chainable
 */
public function wrap($sTemplate="",$Request=NULL)
	{
	$this->sWrapTemplate = $sTemplate;
	return $this;
	}

/**
 * Show WrapTemplate with result of Request as {$Content} 
 * @param $Request mixed Request to process into {$Content}
 * @return string Template result
 */
public function show($Request)
	{
	$Request = new UPCRequest($Request);
	try
		{
		# Execute request
		$mContent = $this->call($Request);
		# DefaultRequest if neccessary
		if($mContent instanceof iUPC) $mContent = $mContent->processDefaultRequest();
		# No request result
		if(!isset($mContent) or ($mContent instanceof iUPC)) throw new E4ExceptionNotFound();
		}
	catch(E4ExceptionNotFound $Exc)
		{
		# Page not found
		header("HTTP/1.0 404 Not Found");
		return $this->page404("/".$Request->RequestString());
		}
	catch(E4ExceptionAccessDenided $Exc)
		{
		# Access Denided
		header("HTTP/1.0 403");	
		return $this->pageAccessDenided(array("required"=>$Exc->sRequered,"page"=>"/".$Request->RequestString()));
		}
	
	# Result withot wrapping
	if(!$this->sWrapTemplate) return $mContent;
	
	# Wrapping with template
	$aData = array
		(
		'Nod'=>$this,
		'Params'=>$this->mWrapParams,
		'Content'=>$mContent
		);
	$Result = T4Templater::Template($this->SelectView($this->sWrapTemplate),$aData);
	
	# Result
	return $Result;
	}
}